import axios from 'axios';
import { Message } from 'element-ui';
const service = axios.create({
    timeout: 600000,
    headers: {

    },
    baseURL: 'http://192.168.4.1/',
});
//http request 拦截器
let request = function (config) {
    // const token = getToken();
    // if (token) { // 判断是否存在token，如果存在的话，则每个http header都加上token
    //     config.headers.token = token;
    // }
    return config;
};
let request_err = function (err) {
    return Promise.reject(err);
};


// http response 拦截器
let response = function (res) {
    const data = res.data;
    // const message = `${data.code}--${data.msg}` || '未知错误'
    const message = `${data.msg}` || '未知错误，请检查网络后重试'

    
    return data;
};

let response_err = function (err) {
    if (err.response) {
        const data = err.response.data;
        const message = `${data.code}--${data.msg}` || '未知错误'
        Message({
            message: message,
            type: 'error',
        })
    }
    return Promise.reject(err);
};

service.interceptors.request.use(request, request_err);
service.interceptors.response.use(response, response_err);
export default service
